package com.todo.strategy.online.application.frontend.controller;

import com.alibaba.fastjson.JSONObject;
import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.application.frontend.service.MemoTemplateAggService;
import com.todo.strategy.online.iface.MemoTemplateFrontendIface;
import com.todo.strategy.online.iface.request.*;
import com.todo.strategy.online.iface.response.MemoTemplateDetailVO;
import com.todo.strategy.online.iface.response.MemoTemplateVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2024/11/29 19:07
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/strategy/memo")
@Tag(name = "备忘录模板前台接口", description = "备忘录模板前台接口")
public class MemoTemplateFrontendController implements MemoTemplateFrontendIface {


    @Resource
    private MemoTemplateAggService memoTemplateAggService;

    @Override
    @Operation(summary = "根据主键Id查询备忘录模板信息")
    @PostMapping("/queryMemoTemplateById")
    public BizResponse<MemoTemplateDetailVO> queryMemoTemplateById(@RequestBody QueryMemoTemplateByIdParam param) {
        if (param == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return memoTemplateAggService.queryMemoTemplateById(param);
    }

    @Override
    @Operation(summary = "查询用户备忘录模板列表")
    @PostMapping("/queryMemoTemplateListByUserId")
    public BizResponse<List<MemoTemplateVO>> queryMemoTemplateListByUserId(@RequestBody QueryMemoTemplateListByUserIdParam param) {
        if (param == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return memoTemplateAggService.queryMemoTemplateListByUserId(param);
    }

    @Override
    @Operation(summary = "查询推荐备忘录信息列表")
    @PostMapping("/queryRecommMemoTemplateList")
    public BizResponse<List<MemoTemplateVO>> queryRecommMemoTemplateList(JSONObject json) {
        return memoTemplateAggService.queryRecommMemoTemplateList();
    }

    @Override
    @Operation(summary = "新增用户备忘录模板信息")
    @PostMapping("/insertMemoTemplate")
    public BizResponse<Boolean> insertMemoTemplate(@RequestBody InsertMemoTemplateParam param) {
        if (param == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return memoTemplateAggService.insertMemoTemplate(param);
    }

    @Override
    @Operation(summary = "更新用户备忘录模板信息")
    @PostMapping("/updateMemoTemplate")
    public BizResponse<Boolean> updateMemoTemplate(@RequestBody UpdateMemoTemplateParam param) {
        if (param == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return memoTemplateAggService.updateMemoTemplate(param);
    }

    @Override
    @Operation(summary = "根据主键Id删除备忘录模板")
    @PostMapping("/removeMemoTemplateById")
    public BizResponse<Boolean> removeMemoTemplateById(@RequestBody RemoveMemoTemplateByIdParam param) {
        if (param == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return memoTemplateAggService.removeMemoTemplateById(param);
    }

    @Override
    @Operation(summary = "根据主键Id拷贝备忘录模板入参")
    @PostMapping("/copyMemoTemplateById")
    public BizResponse<Boolean> copyMemoTemplateById(@RequestBody CopyMemoTemplateByIdParam param) {
        if (param == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return memoTemplateAggService.copyMemoTemplateById(param);
    }
}
